import cv2
import os

def videoToImg(videoFile, timeF):
    videoName = os.path.basename(videoFile)
    outputFile = 'D:/yolo3-keras/output-img/' + videoName
    print('videoFile: ' + videoFile)
    print('outputFile: ' + outputFile)
    vc = cv2.VideoCapture(videoFile)
    c = 1
    num = 0
    if vc.isOpened():
        print('open: ' + videoFile)
        rval, frame = vc.read()
        mkdir(outputFile)
    else:
        print('can not open video')
        rval = False
    while rval:
        rval, frame = vc.read()
        outputPath = ''
        if c % timeF == 0:
            num += 1
            outputPath = outputFile + '/' + str(num) + '.jpg'
            print('outputPath: ' + outputPath)
            cv2.imwrite(outputPath, frame)
        c += 1
        cv2.waitKey(1)
    print("split success")
    width = int(vc.get(cv2.CAP_PROP_FRAME_WIDTH))
    height = int(vc.get(cv2.CAP_PROP_FRAME_HEIGHT))
    print(width, height)
    vc.release()
    return [num, width, height]



def mkdir(path):
 
	folder = os.path.exists(path)
 
	if not folder:                   #判断是否存在文件夹如果不存在则创建为文件夹
		os.makedirs(path)            #makedirs 创建文件时如果路径不存在会创建这个路径
		print("---  new folder...  ---")
		print("---  OK  ---")
 
	else:
		print("---  There is this folder!  ---")
		